import 'package:domeone/childComp.dart';
import 'package:flutter/material.dart';

class statefulComp extends StatefulWidget {
  const statefulComp({super.key, required this.infor});
  final String infor;

  @override
  _statefulCompState createState() => _statefulCompState();
}

class _statefulCompState extends State<statefulComp> {
  int _count = 0;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          Text('我是有状态组件,父组件传的值为：${widget.infor}'),
          Row(
            children: [
              ElevatedButton(
                  onPressed: () {
                    setState(() {
                      _count--;
                    });
                  },
                  child: const Text('-')),
              const SizedBox(width: 10),
              Text(_count.toString()),
              const SizedBox(width: 10),
              ElevatedButton(
                  onPressed: () {
                    setState(() {
                      _count++;
                    });
                  },
                  child: const Text('+'))
            ],
          ),
          childcomp(
            count: _count,
            updataCount: (int count) {
              setState(() {
                _count = count;
              });
            },
          )
        ],
      ),
    );
  }
}
